﻿using System;
using System.Collections.Generic;
using System.Text;
using System.CodeDom;
using System.Collections.ObjectModel;
using CodeDomHelper.Types;

namespace devtm.AutoMapper
{
    [CLSCompliant(false)]
    public class TemplateModelDictionaryInt : ITemplateModel
    {


        public string Name { get { return "DictionaryOfKeyInt"; } }
        public bool NeedParameter { get { return true; } }
        public string DescriptionParameter { get { return "the parameter must be a property integer of the target instance"; } }
        public string Parameter { get; set; }
        public bool IsEnumerable { get { return true; } }
        public string MapperName { get; set; }

        public CodeExpression CreateObject()
        {
            var r = Type.Translate(typeof(Dictionary<,>));
            r.Add(0, typeof(String));
            return new CodeObjectCreateExpression(r.ToString());
        }


        public CodeExpression InsertItem(CodeVariableReferenceExpression item, CodeVariableReferenceExpression target)
        {

            var r = Type.Translate(typeof(Dictionary<,>));
            r.Add(0, typeof(String));

            return

                new CodeMethodInvokeExpression(
                    new CodeMethodReferenceExpression(
                        new CodeCastExpression(r.AssemblyQualifiedName, target), "Add"), new CodePropertyReferenceExpression(item, Parameter), item);

        }


        public TypeExpression Type { get; set; }


    }

}
